<?php
/**
 * Created by PhpStorm.
 * User: kkw
 * Date: 2019/1/28
 * Time: 14:51
 */

namespace kkw\wantbuy\response;
use kkw\user\Util;
use kkw\wantbuy\table\WantBuyTable;
use suda\core\Request;
use suda\core\Response;

class ReleaseWantbuyResponse extends  Response
{

    public function onRequest(Request $request)
    {
        Util::printHeader();

        // 实例化求购信息表
        $want_buy_table = new WantBuyTable();
        // 接收来自前端的数据
        $json = Request::json();

        // 将数据信息插入数据表中
        try {
            $want_buy_table->insert([
                'title' => $json['title'],
                'describe' => $json['describe'],
                'mobile' => $json['mobile'],
                'price' => $json['price'],
                'qq' => $json['qq'],
                'time' => time(),
                'wechat' => $json['wechat'],
                'address' => $json['address'],
            ]);
        } catch (\suda\exception\SQLException $e) {
            $this->json(['code' => 1,'message'=>'发布求购信息失败']);
        }
        $this->json(['code'=> 0 ,'message'=> '发布求购信息成功']);
    }
}